import sys
import configparser
import time
import os
import re
import PyQt5
from PyQt5.QtWidgets import *
from PyQt5.uic import *
from PyQt5.QtCore import *
import socket
import functools
import psutil
import socket
import serial
from time import sleep as sleep


class Thread_IMU_Original_Data_Get(QThread):
    com = None

    def __int__(self):
        pass

    def run(self):
        with open("./data.txt", 'w') as output:
            data = ""
            while True:
                # print('test!')
                # sleep(1)
                data += self.com.read(1000).hex()
                if len(data) > 10:
                    output.writelines(data + "\n")
                    data = ""

    def init_port(self, port_name, port_rate, timeout):
        try:
            self.com = serial.Serial(port_name, port_rate, timeout=timeout)
        except:
            print("port open failed")


if __name__ == "__main__":
    IMU_Original_Data_Get_Thread = Thread_IMU_Original_Data_Get()
    IMU_Original_Data_Get_Thread.init_port("COM3", 961200, 0)
    IMU_Original_Data_Get_Thread.start()
    print('start:')
    while True:
        sleep(10)
        pass
